import pygame
import random

# 初始化 Pygame
pygame.init()

# 设置屏幕尺寸
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Particle System")

# 粒子类
class Particle:
    def __init__(self, x, y):
        self.x = x
        self.y = y
        self.radius = random.randint(1, 5)
        self.color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
        self.vx = random.uniform(-2, 2)
        self.vy = random.uniform(-2, 2)

    def update(self):
        self.x += self.vx
        self.y += self.vy
        self.radius -= 0.1
        if self.radius <= 0:
            particles.remove(self)

    def draw(self):
        pygame.draw.circle(screen, self.color, (int(self.x), int(self.y)), int(self.radius))

particles = []

running = True
clock = pygame.time.Clock()

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        elif event.type == pygame.MOUSEBUTTONDOWN:
            x, y = pygame.mouse.get_pos()
            for _ in range(50):
                particles.append(Particle(x, y))

    screen.fill((0, 0, 0))

    for particle in particles[:]:
        particle.update()
        particle.draw()

    pygame.display.flip()
    clock.tick(60)

pygame.quit()

